package cz.semjob.framework.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class PropertiesUtil {

	private static Logger logger = Logger.getLogger(PropertiesUtil.class);

	public static Properties readProperties(String filePath) throws IOException {
		Properties properties = new Properties();
		InputStream in = new FileInputStream(filePath);
		properties.load(in);
		return properties;
	}

	/**
	 * Get double value.
	 */
	public static Double getDouble(final String str, Properties properties) {
		String value = properties.getProperty(str);
		if (value == null) {
			return null;
		}

		try {
			return Double.parseDouble(value);
		} catch (NumberFormatException ex) {
			logger.warn("Could not read property double value " + value);
			return null;
		}
	}

}
